<template>
    <div class="mainbody">
      <el-row>
        <!-- 获取购物车信息 -->
            <el-col :span="10" v-for="(goods,index) in goodsListChecked" :key="index" style="position: relative;margin:20px 20px">
                <el-card style=" padding: 14px; width: 480px;">
                <el-form>
                    <el-row>
                        <el-col :span="12">
                            <el-form-item>
                                <img :src="goods.goodsImage" width="200px" height="200px" alt="图片为空">
                            </el-form-item>
                        </el-col>
                        <el-col :span="12">
                            <div style="text-align: left;">
                                <el-form-item>
                                    <h2>{{ goods.goodsName }}</h2>
                                    <div class="fontColor" style="height:60px;width:500px;position: relative;top: -15px;"><p>店铺价格 <span ><h2 style="float:left;position:absolute;left: 70px;top: -20px;">¥{{ goods.goodsPrice }}</h2></span></p></div>
                                </el-form-item>
                                <el-form-item label="配送地址">
                                    <el-select v-model="value1" placeholder="请选择收货地址">
                                        <el-option
                                        v-for="item in options"
                                        :key="item.value"
                                        :label="item.address"
                                        :value="item.id">
                                        </el-option>
                                    </el-select>
                                </el-form-item>
                                <el-form-item>
                                    <el-input-number size="mini" v-model="num" controls-position="right" @change="handleChange(goods)" :min="1" :max="goods.goodsInventoryCount"></el-input-number>
                                </el-form-item>
                                <el-form-item>
                                    <el-button @click="removeGoods(index)" type="text" size="small">删除</el-button>
                                    <el-button @click="purchaseGoods(goods,index)" type="text" size="small">购买</el-button>
                                </el-form-item>
                            </div>
                        </el-col>
                    </el-row>
                </el-form>
            </el-card>
            </el-col>
        </el-row>
    </div>
</template>
  
  <script>
  import {userInfo,findGoodsAddress,getCartInfoByUserName } from "../../../ajax/get"
//   import {addGoodsOrder} from "../ajax/post"
//   import defaultValue from "../utils/defalutValue"
  export default {
      name: "getGoodsPay",
      data () {
          return {
            nickName: "", // 昵称
            userName:"",//用户名
            goodsListChecked:[],//购物车列表
            value1: '',//选择收货地址的多选项
            options:[],//收获地址列表
            num:1,
            label: '地址1',
            goodsInventoryCount:0,//库存
          };
      },
      methods: {
              // 查找用户信息
      findUserInfo(userName) {
        userInfo(userName).then(res => {
          console.log("用户信息:",res);
          this.nickName = res.data.data.nickName;
          this.userName = res.data.data.userName;
          //获取购物地址
          findGoodsAddress(res.data.data.userName).then(adr =>{
                console.log("获取的地址",adr);
                this.options=adr.data.data;
                console.log("获取的地址1",this.options);
            })
        })
        //获取购物车数据
        getCartInfoByUserName(userName).then(zxc =>{
            console.log("购物车数据：---",zxc)
            this.goodsList = zxc.data.data;
            this.checkedAllCount=this.goodsList.length; 
            this.goodsListChecked = this.goodsList.map(d=>({
                ...d,
                goodsInventoryCount:0, // 库存
            }))
            console.log("新的购物车数据：---",this.goodsListChecked)
            })
        },
        //删除购物车信息
        removeGoods(index){

        },
        handleChange(goods){
            console.log("商品",goods);
            goodsmes.goodsAllPrice = this.num * goods.goodsPrice;
        },
        //购买商品
        purchaseGoods(goods,index){},
      },
      created() {
      this.findUserInfo(sessionStorage.getItem("userName"));
          
      }
  }
  </script>
  
  <style scoped>
  </style>